package gRpcMiddleware

import (
	"github.com/kataras/golog"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
)

type Middleware func(ctx context.Context) (context.Context, error)

func LoggerMiddleware() grpc.UnaryServerInterceptor {
	return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
		golog.Default.Debugf("method: %s\n(%T)%+v", info.FullMethod, req, req)
		resp, err = handler(ctx, req)
		golog.Default.Debugf("method: %s\nreq: (%T)%+v\nresp: (%T)%+v", info.FullMethod, req, req, resp, resp)
		return
	}
}
